#ifndef QUAD_H
#define QUAD_H

#include "Shape.h"
#include "Polygon.h"

class Cube : public Shape
{
	std::vector<std::pair<int, int>> m_textureCoords;

public:
	const std::vector<std::pair<int, int>>& getTextureCoords() { return m_textureCoords; }
	virtual Shape::Type getType() { return Shape::CUBE; }

	Cube(float w, float h, float z )
	{
		// Definieer cube in een aantal polygonen
		Position cube[8] = 
		{
			Position( -w/2, -h/2, z/2 ),
			Position( w/2, -h/2, z/2 ),
			Position( w/2, -h/2, -z/2 ),
			Position( -w/2, -h/2, -z/2 ),
			Position( -w/2, h/2, z/2 ),
			Position( w/2, h/2, z/2 ),
			Position( w/2, h/2, -z/2 ),
			Position( -w/2, h/2, -z/2 ),
		};

		int polygon[12][3] =
		{
			{0, 1, 4}, // polygon v0,v1,v4
			{1, 5, 4}, // polygon v1,v5,v4
			{1, 2, 5}, // polygon v1,v2,v5
			{2, 6, 5}, // polygon v2,v6,v5
			{2, 3, 6}, // polygon v2,v3,v6
			{3, 7, 6}, // polygon v3,v7,v6
			{3, 0, 7}, // polygon v3,v0,v7
			{0, 4, 7}, // polygon v0,v4,v7
			{4, 5, 7}, // polygon v4,v5,v7
			{5, 6, 7}, // polygon v5,v6,v7
			{3, 2, 0}, // polygon v3,v2,v0
			{2, 1, 0} // polygon v2,v1,v0
		};

		int textureCoords[8][2] =
		{
			{0, 0},
			{1, 0},
			{1, 0},
			{0, 0},
			{0, 1},
			{1, 1},
			{1, 1},
			{0, 1}
		};

		for( int i = 0; i < 12; i++)
		{
			/*** FIRST VERTEX ***/
			m_textureCoords.push_back(std::pair<int, int>(textureCoords[ polygon[i][0] ][0], textureCoords[ polygon[i][0] ][1]));
			Position one( cube[ polygon[i][0] ].x, cube[ polygon[i][0] ].y, cube[ polygon[i][0] ].z);
			m_vertexes.push_back(one);

			/*** SECOND VERTEX ***/
			m_textureCoords.push_back(std::pair<int, int>(textureCoords[ polygon[i][1] ][0],textureCoords[ polygon[i][1] ][1]));
			Position two( cube[ polygon[i][1] ].x, cube[ polygon[i][1] ].y, cube[ polygon[i][1] ].z);
			m_vertexes.push_back(two);

			/*** THIRD VERTEX ***/
			m_textureCoords.push_back(std::pair<int, int>(textureCoords[ polygon[i][2] ][0], textureCoords[ polygon[i][2] ][1]));
			Position three( cube[ polygon[i][2] ].x, cube[ polygon[i][2] ].y, cube[ polygon[i][2] ].z);
			m_vertexes.push_back(three);

			// Bereken face op basis van de 3 punten
			Vector normaalvector = (two-one).uitProduct(three-one);
			m_faces.push_back( normaalvector );

			// Edges
			m_edges.push_back( two-one );
			m_edges.push_back( three-two );
			m_edges.push_back( one-three );
		}

		// Voeg edges toe
		/*m_edges.push_back( Vector(w/2,0,0) );
		m_edges.push_back( Vector(-w/2,0,0) );
		m_edges.push_back( Vector(0,h/2,0) );
		m_edges.push_back( Vector(0,-h/2,0) );
		m_edges.push_back( Vector(0,0,z/2));
		m_edges.push_back( Vector(0,0,-z/2) );*/

	}

};

#endif // QUAD_H